﻿<Window x:Class="SQL_Script_Runner.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:converters="clr-namespace:SQL_Script_Runner"
        Title="SQL Script Runner - Created by Daniel Schroeder - v1.3.3" 
				Height="747" Width="790" ResizeMode="CanMinimize" Icon="/SQL%20Script%20Runner;component/Images/icon.jpg">
	<Window.Resources>
		<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
		<converters:InverseBooleanConverter x:Key="InverseBooleanConverter" />

		<!-- Default all tooltips to show for 60 seconds -->
		<Style TargetType="{x:Type Button}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
		<Style TargetType="{x:Type MenuItem}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
		<Style TargetType="{x:Type TextBox}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
		<Style TargetType="{x:Type CheckBox}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
		<Style TargetType="{x:Type ComboBox}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
		<Style TargetType="{x:Type ListBox}">
			<Setter Property="ToolTipService.ShowDuration" Value="60000" />
		</Style>
	</Window.Resources>
	<Grid>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="39*"/>
			<ColumnDefinition Width="49*"/>
		</Grid.ColumnDefinitions>
		<Button Content="Browse..." Height="23" HorizontalAlignment="Left" Margin="12,137,0,0" Name="btnBrowseForScriptDirectory" VerticalAlignment="Top" Width="75" Click="btnBrowseForScriptDirectory_Click" ToolTip="Browse to find the directory containing the SQL scripts (e.g. stored procedures)." />
		<ComboBox ItemsSource="{Binding Path=Settings.ScriptDirectories, Mode=OneWay}" DisplayMemberPath="" Height="23" HorizontalAlignment="Left" Margin="93,137,0,0" Name="cboScriptDirectories" VerticalAlignment="Top" Width="556" IsEditable="True" DropDownClosed="cboScriptDirectories_DropDownClosed" KeyDown="cboScriptDirectories_KeyDown" KeyUp="cboScriptDirectories_KeyUp" Grid.ColumnSpan="2">
			<ComboBox.ToolTip>
				<TextBlock>The directory containing the scripts to run against the database.<LineBreak />
							Press Enter to commit the current text to the combo boxes items.</TextBlock>
			</ComboBox.ToolTip>
		</ComboBox>
		<Button Content="Refresh" Height="23" HorizontalAlignment="Left" Margin="343,137,0,0" Name="btnRefreshScriptsList" VerticalAlignment="Top" Width="68" Click="btnRefreshScriptsList_Click" ToolTip="Click to refesh the list of scripts to run from the currently selected directory." Grid.Column="1" />
		<ListBox Height="211" HorizontalAlignment="Left" Margin="10,186,0,0" Name="listScriptsToRun" VerticalAlignment="Top" Width="752" SelectionMode="Extended" KeyDown="listScriptsToRun_KeyDown" IsManipulationEnabled="False" AllowDrop="True" Drop="listScriptsToRun_Drop" DisplayMemberPath="FullName" Grid.ColumnSpan="2">
			<ListBox.ToolTip>
				<TextBlock>
						The scripts to run against the database.<LineBreak />
						You can also drag and drop files or folders into this list (Include Sub Directories setting will be used).<LineBreak />
						Only .sql files will be added to this list.<LineBreak />
						Use the Delete key to remove selected items from the list, or click the Remove Selected Scripts button.<LineBreak />
						Use the Ctrl and Shift keys to select multiple files at once; Ctrl+A to select all files.
				</TextBlock>
			</ListBox.ToolTip>
		</ListBox>
		<Button Height="72" HorizontalAlignment="Left" Margin="315,561,0,0" Name="btnSaveAndExit" VerticalAlignment="Top" Width="100" Click="btnSaveAndExit_Click" Content="Save and Exit" ToolTip="Save the current settings and exit." Grid.Column="1" />
		<Button Content="Exit" Height="40" HorizontalAlignment="Left" Margin="315,639,0,0" Name="btnExit" VerticalAlignment="Top" Width="100" Click="btnExit_Click" ToolTip="Exit the application." Grid.Column="1" />
		<Button Content="Remove Selected Scripts" Height="40" HorizontalAlignment="Left" Margin="10,403,0,0" Name="btnRemoveSelectedScripts" VerticalAlignment="Top" Width="166" ToolTip="Click to remove all of the selected scripts from the list of scripts to run." Click="btnRemoveSelectedScripts_Click" />
		<Button Content="RUN SQL SCRIPTS" Height="67" HorizontalAlignment="Left" Margin="218,403,0,0" Name="btnRunScripts" VerticalAlignment="Top" Width="197" ToolTip="Click to run all of the listed scripts against the specified database." Click="btnRunScripts_Click" FontSize="18" Grid.Column="1" />
		<Label Content="SQL Server IP:" Height="28" HorizontalAlignment="Left" Margin="12,12,0,0" Name="label3" VerticalAlignment="Top" />
		<Label Content="Database to run against:" Height="28" HorizontalAlignment="Left" Margin="10,46,0,0" Name="label4" VerticalAlignment="Top" />
		<ComboBox ItemsSource="{Binding Path=DatabaseNames, Mode=OneWay}" DisplayMemberPath="" Height="23" HorizontalAlignment="Left" Margin="151,48,0,0" Name="cboDatabaseNames" VerticalAlignment="Top" Width="286" IsEditable="False" KeyUp="cboDatabaseNames_KeyUp" DropDownClosed="cboDatabaseNames_DropDownClosed" ToolTip="The name of the database to run the scripts against." Grid.ColumnSpan="2" />
		<ComboBox ItemsSource="{Binding Path=Settings.ServerIPs, Mode=OneWay}" DisplayMemberPath="" Height="23" HorizontalAlignment="Left" IsEditable="True" Margin="95,13,0,0" Name="cboServerIPs" VerticalAlignment="Top" Width="213" KeyUp="cboServerIPs_KeyUp" KeyDown="cboServerIPs_KeyDown" DropDownClosed="cboServerIPs_DropDownClosed">
			<ComboBox.ToolTip>
				<TextBlock>The IP Address of the SQL Server to connect to.<LineBreak />
							Press Enter to commit the current text to the combo boxes items.</TextBlock>
			</ComboBox.ToolTip>
		</ComboBox>
		<Button Content="X" Height="23" HorizontalAlignment="Left" Margin="304,137,0,0" Name="btnRemoveScriptDirectory" VerticalAlignment="Top" Width="25" Click="btnRemoveScriptDirectory_Click" ToolTip="Click to remove the current Path from the combo boxes list of directory paths." Grid.Column="1" />
		<Button Content="X" Height="23" HorizontalAlignment="Left" Margin="314,13,0,0" Name="btnRemoveServerIP" VerticalAlignment="Top" Width="25" Click="btnRemoveServerIP_Click" ToolTip="Click to remove the current Server IP from the combo boxes list of IPs." />
		<TextBox Height="203" HorizontalAlignment="Left" Margin="12,476,0,0" Name="txtOutput" VerticalAlignment="Top" Width="640" AcceptsReturn="True" AcceptsTab="True" IsReadOnly="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Auto" Grid.ColumnSpan="2" />
		<Label Content="SQL scripts to run:" Height="28" HorizontalAlignment="Left" Margin="10,160,0,0" Name="label1" VerticalAlignment="Top" />
		<Label Content="Output:" Height="28" HorizontalAlignment="Left" Margin="12,449,0,0" Name="label5" VerticalAlignment="Top" />
		<CheckBox Content="Copy Scripts That Fail To Run To Directory..." IsChecked="{Binding Path=Settings.CopyFailedScriptsToFailedDirectory, Mode=TwoWay}" Height="16" HorizontalAlignment="Left" Margin="182,403,0,0" Name="chkCopyFailedScriptsToFailedDirectory" VerticalAlignment="Top" ToolTip="If checked, this will copy any scripts that fail to run into a specified directory." Grid.ColumnSpan="2" />
		<TextBox Height="23" HorizontalAlignment="Left" Margin="182,420,0,0" Name="txtFailedScriptsDirectory" VerticalAlignment="Top" Width="337" Text="{Binding Path=Settings.FailedScriptsDirectory, Mode=TwoWay}" IsEnabled="{Binding ElementName=chkCopyFailedScriptsToFailedDirectory, Path=IsChecked}" Grid.ColumnSpan="2">
			<TextBox.ToolTip>
				<TextBlock>
					The directory to copy any scripts that fail to run into.<LineBreak />
					If this is left blank a 'Failed Scripts' directory will be created in the same directory as the script that failed to run, and the script will be copied there.<LineBreak />
					Take caution when leaving this blank and using the Include Sub Directories setting, as it will include these 'Failed Scripts' directories.
				</TextBlock>
			</TextBox.ToolTip>
		</TextBox>
		<Button Content="..." Height="23" HorizontalAlignment="Left" Margin="174,420,0,0" Name="btnBrowseForFailedScriptsDirectory" VerticalAlignment="Top" Width="27" IsEnabled="{Binding ElementName=chkCopyFailedScriptsToFailedDirectory, Path=IsChecked}" ToolTip="Browse for the directory to copy scripts that fail to run to." Click="btnBrowseForFailedScriptsDirectory_Click" Grid.Column="1" />
		<Button Content="Force Connect" Height="23" HorizontalAlignment="Left" Margin="345,13,0,0" Name="btnForceConnect" VerticalAlignment="Top" Width="92" Click="btnForceConnect_Click" Grid.ColumnSpan="2">
			<Button.ToolTip>
				<TextBlock>Click this to FORCE a connection to get the list of database names.<LineBreak />
							Use this when you are sure the SQL Server IP is correct, but no Database Names are loading.<LineBreak /></TextBlock>
			</Button.ToolTip>
		</Button>
		<Label Content="Directory containing SQL Scripts To Run:" Height="28" HorizontalAlignment="Left" Margin="10,110,0,0" Name="label6" VerticalAlignment="Top" />
		<CheckBox Content="Include Sub Directories" x:Name="chkIncludeSubDirectories" HorizontalAlignment="Left" Margin="239,116,0,0" VerticalAlignment="Top" Height="16" IsChecked="{Binding Path=Settings.IncludeSubDirectories, Mode=TwoWay}" ToolTip="If checked, all sub directories will also be searched for scripts to run." Checked="chkIncludeSubDirectories_CheckedChanged" Unchecked="chkIncludeSubDirectories_CheckedChanged" Grid.ColumnSpan="2" />
		<CheckBox Content="Only allow CREATE / ALTER PROCEDURE and FUNCTION scripts to run" Height="16" HorizontalAlignment="Left" Margin="14,88,0,0" Name="chkOnlyRunSprocsAndFunctions" VerticalAlignment="Top" IsChecked="True" Grid.ColumnSpan="2">
			<CheckBox.ToolTip>
				<TextBlock>If checked, only scripts that contain "create procedure", "alter procedure", "create function", or "alter function" will run.<LineBreak />
							This is to help prevent accidentally running changescripts. To run changescripts you must uncheck this.</TextBlock>
			</CheckBox.ToolTip>
		</CheckBox>
		<GroupBox Header="Database Authentication" Height="113" HorizontalAlignment="Left" Margin="107,10,0,0" Name="groupBox1" VerticalAlignment="Top" Width="304" Grid.Column="1">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="46*" />
					<ColumnDefinition Width="246*" />
				</Grid.ColumnDefinitions>
				<RadioButton Content="Integrated Security" Height="16" HorizontalAlignment="Left" Margin="6,6,0,0" Name="radIntegratedSecurity" VerticalAlignment="Top" Grid.ColumnSpan="2" IsChecked="{Binding Path=Settings.UseIntegratedSecurity, Mode=TwoWay}" ToolTip="Select this to connect to the database using Integrated Security (i.e. Windows domain credentials)." />
				<RadioButton Content="Username:" Height="16" HorizontalAlignment="Left" Margin="6,31,0,0" Name="radUsernameAndPassword" VerticalAlignment="Top" Grid.ColumnSpan="2" IsChecked="{Binding Path=Settings.UseIntegratedSecurity, Converter={StaticResource InverseBooleanConverter}, Mode=OneWay}" ToolTip="Select this to connect to the database using a username and password." />
				<TextBox Height="23" HorizontalAlignment="Left" Margin="38,28,0,0" Name="txtUsername" VerticalAlignment="Top" Width="202" Grid.Column="1" IsEnabled="{Binding ElementName=radUsernameAndPassword, Path=IsChecked}" Text="{Binding Path=Settings.Username, Mode=TwoWay}" ToolTip="The username to connect to the database with." />
				<TextBlock Height="23" HorizontalAlignment="Left" Margin="25,63,0,0" Name="txtPassword" Text="Password:" VerticalAlignment="Top" Grid.ColumnSpan="2" />
				<PasswordBox Height="23" HorizontalAlignment="Left" Margin="38,61,0,0" Name="pasPassword" VerticalAlignment="Top" Width="121" Grid.Column="1" IsEnabled="{Binding ElementName=radUsernameAndPassword, Path=IsChecked}" ToolTip="The password to connect to the database with." />
				<CheckBox Content="Remember" HorizontalAlignment="Right" Margin="0,64,6,9" Name="chkRememberPassword" Grid.Column="1" IsEnabled="{Binding ElementName=radUsernameAndPassword, Path=IsChecked}" ToolTip="Check this to remember your password for the next time this app is opened." />
			</Grid>
		</GroupBox>
		<StatusBar HorizontalAlignment="Left" Height="24" Margin="0,684,0,0" VerticalAlignment="Top" Width="784" Grid.ColumnSpan="2">
			<TextBlock x:Name="sbtxtTimeStartedRunningScripts" Text="Time Started" ToolTip="The time that the scripts started running." />
			<Separator />
			<TextBlock x:Name="sbtxtElapsedTimeOfRunningScripts" Text="Elapsed Time" ToolTip="How long the scripts have been running for." />
			<Separator />
			<TextBlock x:Name="sbtxtNumberOfScriptsRan" Text="123 of 456" ToolTip="The number of the script currently running, and the total number of scripts to run." />
			<Separator />
			<TextBlock x:Name="sbtxtNameOfCurrentlyRunningScript" Text="Filename of script being ran" ToolTip="The name of the script currently running." />
		</StatusBar>
	</Grid>
</Window>
